package com.datastructure.test.kthinmatrix;

import java.util.*;
import java.util.stream.Collectors;

public class KthinMatrix {

    public static void main(String[] args) {

    }

    public int KthinMatrix (ArrayList<ArrayList<Integer>> matrix, int k) {
        // write code here
        int[] res = new int[matrix.size()*matrix.get(0).size()];
        int index = 0;
        ArrayList<Integer> list;
        for (ArrayList<Integer> integers : matrix) {
            list = integers;
            for (Integer integer : list) {
                res[index]=integer;
                index++;
            }
        }
        Arrays.sort(res);
        return res[k-1];
    }

}
